/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sessionFacades;

import businessObjects.Admin;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import services.AdminServicesLocal;

/**
 *
 * @author williamprado
 */
@Stateless
public class AdminFacade implements AdminFacadeRemote {
    /*@PersistenceContext(unitName = "Adz-ejbPU")
    private EntityManager em;*/

    @EJB
    private AdminServicesLocal adminServices;

    public void registrarAdmin(Admin admin) {
            adminServices.nuevoAdmin(admin);
    }

    public Admin login(String login, String pass){
        Admin ad = adminServices.login(login, pass);
        return ad;
    }

    public Admin consultarAdmin(String login) {
            Admin admin = adminServices.consultarAdmin(login);
            return admin;
    }

    public void actualizarAdmin(Admin admin) {
            adminServices.actualizarAdmin(admin);
    }

    public void eliminarAdmin(String login) {
            adminServices.eliminarAdmin(login);
    }

    public int getBasicRowsParam(){
        return adminServices.leerNumeroFilasBasic();
    }

    public void setBasicRowsParam(int num){
        adminServices.cambiarNumeroFilasBasic(num);
    }

    /*public void create(Admin admin) {
        em.persist(admin);
    }

    public void edit(Admin admin) {
        em.merge(admin);
    }

    public void remove(Admin admin) {
        em.remove(em.merge(admin));
    }

    public Admin find(Object id) {
        return em.find(Admin.class, id);
    }

    public List<Admin> findAll() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Admin.class));
        return em.createQuery(cq).getResultList();
    }

    public List<Admin> findRange(int[] range) {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Admin.class));
        Query q = em.createQuery(cq);
        q.setMaxResults(range[1] - range[0]);
        q.setFirstResult(range[0]);
        return q.getResultList();
    }

    public int count() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<Admin> rt = cq.from(Admin.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }*/

}
